<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<script src="../js/jquery-1.7.2.min.js">

		</script>
	</head>

	<body style="background:#424242">
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript">
			$.ajax({
				url: window.localStorage.getItem("url") + "home/getList",
				data: {
					'uid': window.localStorage.getItem("u_id")
				},
				type: 'GET',
				dataType: 'JSON',
				contentType: "application/x-www-form-urlencoded; charset=UTF-8",

				cache: false,
				processData: true,
				success: function(data) {
					if (data != null) {
						var j = JSON.stringify(data);
						var jsondata = eval('(' + j + ')')
						//console.log( j[0].uid);
						$.each(jsondata, function(i, item) {

							var li =
								'<li class="mui-table-view-cell"><div class="mui-table"><div class="mui-table-cell mui-col-xs-10"><h4 class="mui-ellipsis">' +
								item.title + '</h4><h5 id="' + item.qid + '" class="' + item.aid + '">' + item.context +
								'</h5><p class="mui-h6 mui-ellipsis">回答者：' +
								item.uname +
								'</p></div><div class="mui-table-cell mui-col-xs-2 mui-text-right"><span class="mui-h5"></span></div></div></li>';
							$("#ul").append(li);

						});

					} else {
						mui.toast('不知道怎么肥事，不起作用了┐(´∇｀)┌');
					}
					var obj_lis = document.getElementById("ul").getElementsByTagName("h5");
					for (i = 0; i < obj_lis.length; i++) {
						obj_lis[i].onclick = function() {
							window.localStorage.setItem("aid", this.getAttribute("class"));
							$.ajax({
								url: window.localStorage.getItem("url") + "home/log",
								data: {
									'readLog.aid': this.getAttribute("class"),
									'readLog.qid': this.getAttribute("id"),
									'readLog.uid': window.localStorage.getItem("u_id")
								},
								type: 'GET',
								dataType: 'JSON',
								contentType: "application/x-www-form-urlencoded; charset=UTF-8",

								cache: false,
								processData: true,
								success: function(data) {
									mui.openWindow({
										url: './answerInfo.html',
									});
								},
								error: function(XMLHttpRequest, textStatus, errorThrown) {
									//异常处理；
									alert(textStatus);
								}
							});
						}
					}
				},
				error: function(XMLHttpRequest, textStatus, errorThrown) {
					//异常处理；
					alert(textStatus);
				}
			});
			mui.init({
				gestureConfig: {
					longtap: true //默认为false
				},
				pullRefresh: {
					swipeBack: false,
					container: "#pullrefresh", //下拉刷新容器标识，querySelector能定位的css选择器均可，比如：id、.class等
					up: {

						callback: function() {
							setTimeout(function() { //定时器，提升用户体验
								$.ajax({
									url: window.localStorage.getItem("url") + "home/getList",
									data: {
										'uid': window.localStorage.getItem("u_id")
									},
									type: 'GET',
									dataType: 'JSON',
									contentType: "application/x-www-form-urlencoded; charset=UTF-8",

									cache: false,
									processData: true,
									success: function(data) {
										if (data != null) {
											var j = JSON.stringify(data);
											var jsondata = eval('(' + j + ')')
											//console.log( j[0].uid);
											$.each(jsondata, function(i, item) {

												var li =
													'<li class="mui-table-view-cell"><div class="mui-table"><div class="mui-table-cell mui-col-xs-10"><h4 class="mui-ellipsis">' +
													item.title + '</h4><h5 id="' + item.qid + '" class="' + item.aid + '">' + item.context +
													'</h5><p class="mui-h6 mui-ellipsis">回答者：' +
													item.uname +
													'</p></div><div class="mui-table-cell mui-col-xs-2 mui-text-right"><span class="mui-h5">12:25</span></div></div></li>';
												$("#ul").append(li);

											});

										} else {
											mui.toast('不知道怎么肥事，不起作用了┐(´∇｀)┌');
										}
										var obj_lis = document.getElementById("ul").getElementsByTagName("h5");
										for (i = 0; i < obj_lis.length; i++) {
											obj_lis[i].onclick = function() {
												window.localStorage.setItem("aid", this.getAttribute("class"));
												$.ajax({
													url: window.localStorage.getItem("url") + "home/log",
													data: {
														'readLog.aid': this.getAttribute("class"),
														'readLog.qid': this.getAttribute("id"),
														'readLog.uid': window.localStorage.getItem("u_id")
													},
													type: 'GET',
													dataType: 'JSON',
													contentType: "application/x-www-form-urlencoded; charset=UTF-8",

													cache: false,
													processData: true,
													success: function(data) {
														mui.openWindow({
															url: './answerInfo.html',
														});
													},
													error: function(XMLHttpRequest, textStatus, errorThrown) {
														//异常处理；
														alert(textStatus);
													}
												});
											}
										}
									},
									error: function(XMLHttpRequest, textStatus, errorThrown) {
										//异常处理；
										alert(textStatus);
									}
								});
								mui.toast('更新成功！(ノ°▽°)ノ');
								mui('#pullrefresh').pullRefresh().endPullupToRefresh(); //完成刷新
							}, 1500);

						} //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
					}
				}
			})
		</script>
		<div class="mui-content" id="pullrefresh">
			<ul id="ul" class="mui-table-view mui-table-view-striped mui-table-view-condensed">

			</ul>
		</div>

	</body>

	<script>
		
	</script>
</html>
